<template>
  <div class="box">
    <el-form label-position="right" :model="fromData" inline size="small ">
      <el-form-item label="挂靠点ID" label-width="70px">
        <el-input v-model="fromData.userName"></el-input>
      </el-form-item>
      <el-form-item label="挂靠点" class="ml-6" label-width="80px">
        <el-input v-model="fromData.name"></el-input>
      </el-form-item>
      <el-form-item label="门店性质" class="ml-6" label-width="80px">
        <el-select v-model="value" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>

      </el-form-item>


      <el-form-item label="" class="ml-2">
        <el-button type="primary" icon="el-icon-search">查询</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">新增</el-button>
        <el-button class="mr-2" type="info" plain>清空条件</el-button>
      </el-form-item>


    </el-form>

    <div class="table" style="height: 690px;">
      <el-table :data="tableData" border style="width: 100%" height="100%">
        <el-table-column prop="date" type="index" label="序号" sortable width="100" align="center">
        </el-table-column>
        <el-table-column prop="cid" label="挂靠点ID" sortable width="250" align="center">
          <template slot-scope="scope">
                <span style="color: #4d4de2;cursor: pointer;" @click="go(scope.row)">{{ scope.row.cid }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="com_name" label="挂靠点" sortable align="center">
        </el-table-column>
        <el-table-column prop="iscid" label="门店性质" sortable align="center">
        </el-table-column>
        <el-table-column prop="cooperation" label="合作状态" sortable align="center">
          <template slot-scope="scope">
           <span>{{ scope.row.cooperation ? '合作中' : '不合作' }}</span>
          </template>

        </el-table-column>
        <el-table-column prop="line" label="排序" sortable align="center">
        </el-table-column>
        <el-table-column prop="address" label="操作" align="center">
          <el-button type="primary" plain size="mini">编辑</el-button>
          <el-button type="danger" plain size="mini">删除</el-button>
        </el-table-column>
      </el-table>
    </div>

    <!-- 编辑和新增弹窗 -->
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible" width="800px">
      <el-form :model="form">
        <el-form-item label="活动名称" label-width="120px">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动区域" label-width="80px">
          <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 分页 -->
    <div class="pagin">
      <el-pagination background :current-page="initParams.page" :page-sizes="[20, 50, 100, 150]"
            :page-size="initParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script>
/**
* @author        chenRong
* @time          2023-11-03 15:03:34  星期五
* @description   
**/
import { oldLoginSystem } from '@/utils/publicMethod'
import { ComNameHandlerAPI } from "@/api/adminstare";
export default {
  data() {
    return {
      fromData: {
        name: '',
        userName: ""
      },
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      options: [{
        value: '0',
        label: '挂靠点'
      }, {
        value: '1',
        label: '直营点'
      }],
      value: '',
      gridData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }],
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      // 初始化参数
      initParams: {
        page: 1,
        pageSize: 20,
      },
      // 分页总条数
      total: 0,
    }
  },
  mounted() { 
    this.getListData()
  },
  computed:{ 
    cooperation(){ 
      return  this.tableData.map(v => { 
        return v.cooperation
      })
    }
  },
  methods: {
    async getListData() { 
      const data = {
        action: 'comNameList',
        page: this.initParams.page,
        pageSize: this.initParams.pageSize,
        sortStr: "cid desc",
      }
      const result = await ComNameHandlerAPI(data)

      this.total=result.total

      this.tableData= result.data
    },
    // 当前显示的条数 发生改变时触发
    handleSizeChange(pageSize) {
      this.initParams.pageSize = pageSize || 20
      this.getListData()
    },
    // 当前页码发生改变时触发
    handleCurrentChange(page) {
      this.initParams.page = page || 1
      this.getListData()
    },
    // 点ID跳旧版
    go(val) {
      // http://jx.qida999.com/DriverCommon/driver/DrCom_nameUserno.html?cid=9039
      const redirectUrl = `http://jx.qida999.com/drivercommon/driver/DrCom_nameUserno.html?cid=${val.cid}`
      const url = 'http://jx.qida999.com/DriverCommon/CommApiNew/login/Login.aspx'
      oldLoginSystem(redirectUrl, url)
    },
  }
}
</script>

<style lang="scss" scoped>
.box {
  background-color: white;
  padding: 20px;
  // height: 700px;
}

.title {
  margin-bottom: 20px;
  color: #333;
}

.pagin {
  height: 50px;
  width: 100%;
  display: flex;
  justify-content: end;
  align-items: end;
}
</style>